package org.shj.spring.boot.lang;

import com.alibaba.fastjson.JSONObject;

/**
 * @author sunchenjie
 * @date 2017/12/23 0027
 */
public class JsonMapper {
    /**
     * Json转换接口的时候会转换为代理对象
     * 需进行二次转换
     *
     * @param o
     * @param clazz
     * @return
     */
    public static <T> T convertFromInterface(Object o, Class clazz) {
        String string = JSONObject.toJSONString(o);
        Class<? extends T> entityClazz = (Class<T>) BeanMapper.newInstance(clazz).getClass();
        T object = JSONObject.parseObject(string, entityClazz);

        return object;
    }

}
